<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/vue-2.6.7.js"></script>
</head>
<body>
    <div id="app" style="text-align:center">
        <h1>{{message}}</h1>
        <input type="button" value="开始" @click="cyclicLamp">
        <input type="button" value="暂停" @click="stop">
    </div>
    <script>
        const vm = new Vue({
            el:"#app",
            data:{
                timeInterval:null,//存放定时器
                "message":"猥琐发育，别浪~~!"
            },
            methods: {
                cyclicLamp:function(){
                    //不能重复开启定时器
                    if(this.timeInterval!=null) return;
                    this.timeInterval=setInterval(()=>{
                        this.message=this.message.slice(1)+this.message.charAt(0)
                    },300)
                    console.log(this.timeInterval)
                },
                stop:function(event){
                    clearInterval(this.timeInterval)
                    console.log(typeof this.timeInterval)
                    //释放引用
                    this.timeInterval=null;
                }
            },
        })
    </script>
</body>
</html>